from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
url = 'file:///C:/Users/%E6%9D%8E%E8%8A%B8/Desktop/f/%E4%BD%9C%E4%B8%9A/code/automated_testing/day3/html/popup.html'
driver.get(url)

# 找到弹窗并点击
btn_list = driver.find_elements(By.TAG_NAME,'button')
btn_list[0].click()

# 切换到弹窗
alter = driver.switch_to.alert
# 确定按钮
alter.accept()

# confirm 有确定和取消两种方法
btn_list[1].click()
alter = driver.switch_to.alert
# 取消按钮
alter.dismiss()

# prompt 有输入框，以及取消和确定三种方法
btn_list[2].click()
alter = driver.switch_to.alert
alter.send_keys('ok')

print(alter.text)
# 退出游览器
driver.quit()